package com.jh.service;
//包都是jdk自带的
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class BillProxy implements InvocationHandler{

	//不让外面实例化
	private BillProxy() {}
	//当前代理的对象
	private Object target;
	
	public static Object getInstance(Object o) {
	BillProxy billProxy = new BillProxy();
		//将被代理对象赋值给代理对象
	billProxy.target=o;
		//获取代理对象的类加载器、接口
	return Proxy.newProxyInstance(o.getClass().getClassLoader(), o.getClass().getInterfaces(), billProxy);
		
	}
	
	public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
		System.out.println("watch out");
		
		Object object = method.invoke(target, args);
		
		System.out.println("bill");
		return object;
	}

}
